<template>
  <!-- 固定宽高比的盒子，兼容处理aspect-ratio -->
  <div class="outer-box">
    <div class="inner-box">
      <div class="aspect-content">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import type { AspectBoxProps } from '../types'

const props = withDefaults(defineProps<AspectBoxProps>(), {
  aspectRatio: 1
})

const paddingPercent = computed(() => {
  return `${props.aspectRatio * 100}%`
})
</script>

<style lang="scss" scoped>
.outer-box {
  width: 100%;

  .inner-box {
    padding-top: v-bind(paddingPercent);
    position: relative;

    .aspect-content {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
    }
  }
}
</style>
